package com.zyh.homework;

public class Test7 {
    public static void main(String[] args) {
        /*
        定义一个方法,求出给定的数字在给定int型数组中出现的次数,如果一次没有出现则返回0
        如:给定数字3 求出3在数组 int[] arr = {3,4,3,5,7,9};中出现的次数
         */
        int[] arr={3,4,3,5,7,9};
        int count = getCount(arr, 8);
        System.out.println("count = " + count);
    }
    public static int getCount(int[] arr,int key){
        int count=0;
        for (int i = 0; i < arr.length; i++) {
            if (key==arr[i]){
                count++;
            }
        }
        if (count==0){
            System.err.println(key+"不在数组中！");
            return 0;
        }
        return count;
    }
}
